/**
 * Created by forcht on 2018/5/16.
 */
public class Solution {
    public int lengthOfLongestSubstring(String s) {
        int max=0;
        int i=0;
        StringBuilder str=new StringBuilder();
        while (i<s.length()){
            int index=str.indexOf(s.charAt(i)+"");
            if(index==-1){
                str.append(s.charAt(i));
            }else {
                if(str.length()>max)max=str.length();
                str.delete(0,index+1);
                str.append(s.charAt(i));
            }
            i++;
        }
        if(str.length()>max)max=str.length();
        return max;
    }

//    public static void main(String[] args) {
//        Solution solution=new Solution();
//        System.out.println(solution.lengthOfLongestSubstring("qopubjguxhxdipfzwswybgfylqvjzhar"));
//    }
}
